package SecondeStage.IO.In_OutputStream;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class FileCopy {
    public static void main(String[] args) {
        // 完成文件拷贝
        FileInputStream fileInputStream = null;
        FileOutputStream fileOutputStream =null;

        String SrcfilePath ="D:\\Java\\JavaProject\\a.txt";
        String DestSrcfilePath ="D:\\Java\\JavaProject\\b.txt";
        try {
            fileInputStream=new FileInputStream(SrcfilePath);
            fileOutputStream=new FileOutputStream(DestSrcfilePath);
            // 定义一个字节数组，提高读取效率
            byte[] buf =new byte[1024];
            int readLen = 0;
            while ((readLen = fileInputStream.read(buf))!= -1){
                // 读取到后，就写入到文件，通过 fileOutputStream. 即一边读一边写
                fileOutputStream.write(buf,0,readLen);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }finally {
                try {
                    if(fileInputStream !=null){
                        fileInputStream.close();
                    }
                    if (fileOutputStream!=null){
                        fileOutputStream.close();
                    }
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
        }
    }
}
